/**
 * 
 */
package com.hoopchina.ui.search;

import com.hoopchina.news.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 搜索提醒listview
 * @author Guo Baiyu
 *
 */
public class SearchJsonList extends LinearLayout {

	private Context	                mContext	        = null;
	private ListView	            mSearchJsonListView	= null;
//	private Button	                mCloseButton	    = null;
	private TextView	            mJsonLoadingText	= null;
	private LinearLayout	        mSearchJsonView	    = null;
	private ISearchJsonListListener	mListener	        = null;

    /**
     * @param context
     */
    public SearchJsonList( Context context ) {
        super( context );
        mContext = context;
        init();

    }

    /**
     * @param context
     * @param attrs
     */
    public SearchJsonList( Context context, AttributeSet attrs ) {
        super( context, attrs );
        mContext = context;
        init();
    }
    
    /**
     * 
     */
    private void init() {
        // 布局
        String infServiString = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater lInflater;
        lInflater = ( LayoutInflater ) mContext.getSystemService( infServiString );
        mSearchJsonView = (LinearLayout) lInflater.inflate( R.layout.searchjsonlist, this, true );
        
        mJsonLoadingText =( TextView ) mSearchJsonView.findViewById( R.id.textViewJsonLoading );
        
        mSearchJsonListView = ( ListView ) mSearchJsonView.findViewById( R.id.listViewSearchJson );
        mSearchJsonListView.setOnItemClickListener( new OnItemClickListener() {
            @Override
            public void onItemClick( AdapterView<?> parent, View view, int position, long id ) {
                String searchText = ((SearchJsonListTextItem)view).getItemText().trim();
                mListener.onJsonListItemClick( searchText );
            }
            });
        

    }
    
    void setListener( ISearchJsonListListener listener) {
        mListener = listener;
    }
    /**
     * 
     */
    public void setJosnViewVisibility(int visibility) {
        if ( mSearchJsonView.getVisibility() != visibility ) {
            mSearchJsonView.setVisibility( visibility );
        }
    }
    
    void setAdapter(SearchJsonListAdapter adapter) {
        mSearchJsonListView.setAdapter( adapter );
    }
    
    public void displayJosnLoading(boolean isDisp) {
        if (isDisp) {
            mJsonLoadingText.setVisibility(  TextView.VISIBLE ); 
        }else {
            mJsonLoadingText.setVisibility(  TextView.GONE ); 
        }
    }
//    public void  addFooterViewForClearButton() {
//		LayoutInflater inflater = 
//				( LayoutInflater )getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
//			inflater.inflate( R.layout.searchsuglistclose, this, true );
//			
//			LinearLayout layout = ( LinearLayout )findViewById( R.id.linearLayoutSearchSugClose );
//			
//			Button closeButton = ( Button ) layout.findViewById( R.id.buttonCloseJsonList );
//			closeButton.setOnClickListener( new OnClickListener() {
//            @Override
//            public void onClick( View v ) {
//                // TODO Auto-generated method stub
//                setJosnViewVisibility( SearchJsonList.GONE );
//            }
//        });
//        mSearchJsonListView.addFooterView(layout);
//    }

}
